package com.oscar.ehome.view.messageview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.bean.messageBean.MessageLeveBean;

import java.util.List;

/**
 * Created by oscar
 * author: MengWanhe
 * date: On 2017/7/11
 * 发布通知页面职级
 */

public class IssuemessageAdapter extends BaseAdapter {

    private List<MessageLeveBean.ListBean> specailList;
    private LayoutInflater mInflater;
    private Context mContext = null;
    int checks = 2;
    public OnClickedlister onClickListener;
    int size = 0;

    public IssuemessageAdapter(Context context, List<MessageLeveBean.ListBean> list) {
        this.mContext = context;
        this.specailList = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setList(List<MessageLeveBean.ListBean> list, int checks) {
        this.specailList = list;
        this.checks = checks;
        notifyDataSetChanged();
    }

    /**
     * 设置回调接口
     *
     * @param onClickListener
     */
    public void setOnClickedListener(OnClickedlister onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickedlister {
        public void OnClick(int postion);
    }

    @Override
    public int getCount() {
        if (specailList.size() > 0) {
            size = specailList.size() + 1;
        } else {
            size = specailList.size();
        }
        return size;
    }

    @Override
    public Object getItem(int position) {
        return specailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_issuemessage, null);
            holder = new ViewHolder();
            holder.message_leve = (TextView) convertView.findViewById(R.id.message_leve);
            holder.message_people_chiefs = (CheckBox) convertView.findViewById(R.id.message_people_chiefs);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }
        if (specailList.size() > 0) {
            if (position == specailList.size()) {
                holder.message_leve.setText("全部");
            } else {
                holder.message_leve.setText(specailList.get(position).getRoleName());
            }
            if (checks == 1) {
                holder.message_people_chiefs.setChecked(true);
            }else if(checks == 0){
                holder.message_people_chiefs.setChecked(false);
            }
        }

        holder.message_people_chiefs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickListener.OnClick(position);
            }
        });

        return convertView;
    }

    class ViewHolder {
        TextView message_leve;
        CheckBox message_people_chiefs;
    }

}
